package com.zou.config;

import com.zou.commons.constants.Constants;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginHandlerInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        // 登录成功应有用户的session
        Object loginUser = request.getSession().getAttribute(Constants.SESSION_USER);
        if (loginUser == null) { // 没有登录
            request.getRequestDispatcher("/backstage/login").forward(request, response);
            return false;
        }
        return true;
    }
}
